extends BoarStatusBase

func start():
	actor.play_animation("Hurt")

func run_physics_process(delta)->void:
	actor.move_and_slide()
	if actor.is_play_animation("Hurt"):
		return
		
	if actor.velocity.x == 0:
		return change_status("Run")

func run_process(delta)->void:
	if is_weak():
		return change_status("Retreat")
	hurt_velocity(delta)
	
# 击退处理
func hurt_velocity(delta:float)->void:
	# 击退方向
	if blackboard.has_damage():
		var dir :Vector2 
		var damage:Damage = blackboard.get_damage() 
		if damage.type == 1:
			dir = blackboard.get_damage().source.global_position.direction_to(actor.global_position)
			if dir.x > 0:
				actor.face_direction(actor.Direction.LEFT)
			elif dir.x < 0:
				actor.face_direction(actor.Direction.RIGHT)
		elif damage.type == 2:
			dir = Vector2(-blackboard.direction, 0)
			
		actor.velocity = dir * 200
		blackboard.free_damage()
	else:
		actor.velocity.y += blackboard.gravity * delta
		actor.velocity.x=move_toward(actor.velocity.x, 0.0 , blackboard.max_speed /  0.2 * delta)
	
